<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="icon" href="img/favicon.ico">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/vendor.min.css">
    <link rel="stylesheet" href="css/plugins.min.css">
    <link rel="stylesheet" href="css/style.min.css">
    <style>
        .pwdetable-box {
            margin-top: 40px;
            padding: 0px 30px;
        }
        .pwde-table {
            width: 100%;
            text-align: center;
            border: solid 1px black;
        }
        .pwde-tr {
            background-color: #006fb7;
        }
        .pwde-table tr, td, th {
            height: 40px;
            border: solid 1px black;
        }
        html{
            height: 100%;
            overflow-y: hidden;
        }
        body{
            height: 100%;
            overflow-y: auto;
        }
        .aaa{
            padding:0 15px;height:35px;line-height:32px;font-size:14px;text-transform:uppercase
        }
    </style>
</head>
<body>

<div class="container" style="margin-top: 20px;">
    <div class="row">
        <h2 class="title">国际通话费用</h2>
    </div>
    <div style="margin-top: 20px;">
        <caption><h3 class="title">按国家名称/国家或地区代码搜索</h3></caption>
        <div style="display: flex;justify-content: space-between;align-items: center; height: 50px;">
            <div>
                展示
                <select style="border: 1px solid black; height: 30px; width: 50px; border-radius: 4px;" id="limit" onchange="getPageLimit()">
                    <option>2</option>
                    <option>3</option>
                    <option>5</option>
                    <option selected>20</option>
                    <option>30</option>
                </select>
                条数据
            </div>
            <div>
                搜索：<input type="text" id="key" style="border: 1px solid black; height: 30px; width: 210px;  border-radius: 4px;">
            </div>
        </div>
        <table class="pwde-table">
            <thead>
                <tr class="pwde-tr" style="color: white;">
                    <th width="10%">序号</th>
                    <th>国家名称</th>
                    <th>国家代码</th>
                    <th>价格（KIP/mn）</th>
                </tr>
            </thead>
            <tbody id="test">

            </tbody>
        </table>
        <div style="display: flex;justify-content: space-between;align-items: center; height: 50px;">
            <div>

            </div>
            <div>
                <button style="padding: 0px 10px; size: 30px" onclick="toPage(1)"><</button>
                <input type="text" style="border: 1px solid black;height: 30px;width: 40px;border-radius: 4px;text-align: center;" value="1" id="page">
                <button style="padding: 0px 10px; size: 30px" onclick="toPage(2)">></button>
            </div>
        </div>
    </div>
</div>

<div class="product-tab-area section-space-top-100" style="padding-bottom: 50px;">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <ul class="nav product-tab-nav product-tab-style-2" role="tablist">
                    <li class="nav-item" role="presentation">
                        <a class="active btn aaa" id="description-tab" data-bs-toggle="tab"
                           href="#description" role="tab" aria-controls="description" aria-selected="true">
                            如何使用
                        </a>
                    </li>
                </ul>
                <div class="tab-content product-tab-content">
                    <div class="tab-pane fade show active" id="description" role="tabpanel"
                         aria-labelledby="description-tab">
                        <div class="product-description-body">
                            <p class="short-desc mb-0" id="product"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="js/vendor.min.js"></script>
<script src="js/plugins.min.js"></script>
<script src="js/main.min.js"></script>
<script src="layui/layui.js"></script>
<script src="js/token.js"></script>
<script src="js/config.js"></script>
<script src="js/jquery.i18n.min.js"></script>
<script src="js/multi_lang_config.js"></script>
<script>

    var layer = layui.layer;
    var form = layui.form;

    var moduleName = "subMain";
    var defaultLang = layui.data('langTab').langType;
    initLangConfig({
        defaultLang:defaultLang,
        filePath: "js/i18n/"+moduleName+"/",
        module:moduleName,
        base:"js/"
    })
    var i18np = null;
    function changeLang(lang) {
        defaultLang = lang;
        reloadI18n({
            defaultLang:lang,
            filePath: "js/i18n/"+moduleName+"/",
            module:moduleName,
        })
        i18np.loadProperties(moduleName);
        gjtelfyDataInit();
    }

    layui.config({base: 'js/'})
        // 继承treetable.js插件
        .extend({i18np: 'i18n'}).use([ 'i18np','jquery'], function () {
        i18np = layui.i18np;
        i18np.loadProperties(moduleName);
    });

    var gjtelfyData = {};
    function gjtelfyDataInit(){
        if (defaultLang == "zh") {
            $('#product').html(gjtelfyData.contentZh);
        } else if (defaultLang == "la") {
            $('#product').html(gjtelfyData.contentLao);
        } else if (defaultLang == "en") {
            $('#product').html(gjtelfyData.contentEn);
        }
    }

    $(function () {
        getData();
        getTableData();
    })

    function getData() {
        $.ajax({
            url: HOST + "phoneOrSales/getPhoneOrSalesByType?type=3",
            type: "GET",
            success: function (res) {
                gjtelfyData = res.data;
                gjtelfyDataInit();
            }
        })
    }

    //总页数
    var totalPage = 1;
    //上一页、下一页
    function toPage(param) {
        var page = $("#page").val();
        if (param == 1){
            if (page > 1){
                page--;
            }else{
                page = 1;
            }
        }else if (param == 2){
            if (page >= totalPage){
                page = totalPage;
            }else{
                page++;
            }
        }
        $("#page").val(page);
        getTableData();
    }

    function getPageLimit() {
        $("#page").val(1);
        getTableData();
    }

    function getTableData() {
        let page = $("#page").val();
        let limit = $('#limit').val();
        $.ajax({
            url: HOST + "webapi/internationalCall/getInternationalCallByPage",
            type: "GET",
            data:{
                page:page,
                limit:limit,
                key:$("#key").val()
            },
            success: function (res) {
                var trRow = res.data;
                var count = res.count;
                totalPage = count < limit ? 1 : (count%limit==0 ? (count/limit).toFixed(0) : (count/limit + 1).toFixed(0));
                var str1 = "";
                for (var i = 0; i < trRow.length; i++) {
                    let lie=i+1;
                    str1 += "<tr>" + "<td>" + lie + "</td>" +
                        "<td>" + trRow[i].country.countryName + "</td>" +
                        "<td>" + trRow[i].country.code + "</td>" +
                        "<td>" + trRow[i].price + "</td>" +
                        "</tr>";
                }
                test.innerHTML = str1;
            }
        })
    }

    //监听回车事件
    $(window).keypress(function (event) {
        if(event.which === 13){
            getTableData();
        }
    })

</script>
</body>
</html>